<?php if(!defined('BASEPATH'))exit('No direct script access allowed');

class timkiem extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->library('addin');
	}
	public function index($sotrang=1)
	{
		if(!isset($_GET['search'])||$_GET['search']==NULL) echo redirect(base_url());
		if(!is_numeric($sotrang)) $sotrang = 1;
		$this->load->model('sanpham_model');
		$str = $this->input->get('search',TRUE);
		$data2['sanpham'] = $this->sanpham_model->getSearch($str,$sotrang);
		
		$this->load->library('pagination');
		$config['base_url'] = base_url('timkiem/index');
		$config['first_link'] = '<<';
		$config['last_link'] = '>>';
		$config['anchor_class'] = 'class="pagin"'; 
		$config['total_rows'] = $this->sanpham_model->countSearch($str);
		$config['per_page'] = 1;
		$config['use_page_numbers'] = TRUE;
		$this->pagination->initialize($config);
		$data2['phantrang'] = $this->pagination->create_links();
		
		$data1['thongke'] = $this->addin->thongKe();
		$data1['counter'] = $this->addin->getcounter();
		$data1['online'] = $this->addin->getonline();
		$data1['menu1'] = $this->addin->getMenuMain();
		$data1['menu2'] = $this->addin->getMenu3Cap();
		$data1['noibat'] = $this->sanpham_model->getNoiBat();
		$this->load->view('required/header-trangcon',$data1);
		$this->load->view('timkiem/index',$data2);
		$this->load->view('required/footer',TRUE);
		$this->output->enable_profiler(TRUE);
		//result [] sản phẩm tìm kiếm
		//counter : int : So nguoi da truy cap
		//online : int : So nguoi dang online
		//$menu1 : string (Chỉnh sửa lại chuỗi xuất ra)
		//$menu2 : string (Chỉnh sửa lại chuỗi xuất ra)
	}
}